T
CSharpTest.Net
InstanceFactory<T> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Interfaces Namespace : InstanceFactory<T> Class

Glossary Item Box

A factory that always returns the same instance of an object each time Create() is called.

Syntax

Visual Basic (Declaration) 
Public Class InstanceFactory(Of T) 
   Implements IFactory(Of T) 
C# 
public class InstanceFactory<T> : IFactory<T>  

Type Parameters

T

Example

Library/Library.Test/TestFactories.cs

C#Copy Code
TestObject obj = new TestObject();
IFactory<TestObject> factory = new InstanceFactory<TestObject>(obj);
Assert.IsTrue(ReferenceEquals(obj, factory.Create()));
Assert.IsTrue(ReferenceEquals(factory.Create(), factory.Create()));
VB.NETCopy Code
Dim obj As New TestObject()
Dim factory As IFactory(Of TestObject) = New InstanceFactory(Of TestObject)(obj)
Assert.IsTrue(ReferenceEquals(obj, factory.Create()))
Assert.IsTrue(ReferenceEquals(factory.Create(), factory.Create()))

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Interfaces.InstanceFactory<T>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys